﻿namespace MatrixField
{
    using System;
    using System.Linq;

    public class Direction
    {
        private int row;
        private int col;

        public int Row
        {
            get
            {
                return this.row;
            }

            set
            {
                if (value < -1 || value > 1)
                {
                    throw new ArgumentOutOfRangeException("Direction Row can have only -1,0 and 1 as a value.");
                }

                this.row = value;
            }
        }

        public int Col
        {
            get
            {
                return this.col;
            }

            set
            {
                if (value < -1 || value > 1)
                {
                    throw new ArgumentOutOfRangeException("Direction Col can have only -1,0 and 1 as a value.");
                }

                this.col = value;
            }
        }

        public DirectionName Name { get; set; }
       
        public void ChangeDirection()
        {
            switch (this.Name)
            {
                case DirectionName.DownRight:
                    this.Name = DirectionName.Left;
                    this.Row = 0;
                    this.Col = -1;
                    break;
                case DirectionName.Left:
                    this.Name = DirectionName.Up;
                    this.Row = -1;
                    this.Col = 0;
                    break;
                case DirectionName.Up:
                    this.Name = DirectionName.DownRight;
                    this.Row = +1;
                    this.Col = +1;
                    break;
                case DirectionName.Right:
                    this.Name = DirectionName.Down;
                    this.Row = +1;
                    this.Col = 0;
                    break;
                case DirectionName.Down:
                    this.Name = DirectionName.UpLeft;
                    this.Row = -1;
                    this.Col = -1;
                    break;
                case DirectionName.UpLeft:
                    this.Name = DirectionName.Right;
                    this.Row = 0;
                    this.Col = +1;
                    break;
            }
        }
        //// public override string ToString()
        //// {
        ////     return string.Format("Name: {0}, DirectionRow: {1}, DirectionCol: {2}", this.Name, this.Row, this.Col);
        //// }
    }
}